package leetcode.L500;

import java.util.ArrayList;
import java.util.List;

public class EX77 {
    int deepl = 0; //搜索深度
    int nl = 0;

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        deepl = k;
        nl = n;
        int deep = 0;
        dfs(res,path,deep,1);
        return res;
    }

    private void dfs(List<List<Integer>> res, List<Integer> path, int deep,int now) {
        if(deep == deepl){
            res.add(new ArrayList<>(path));
            return;
        }

        for (int i = now; i <= nl ; i++) {
            path.add(i);
            dfs(res,path,deep+1,i+1);
            path.remove(path.size()-1);

        }

    }
}
